package comm.test.bean;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

/**
 * @author WangLin
 * @packageName
 * @ClassName CompanyAspect
 * @date 2020/11/12 15:30
 * @description
 */
public class CompanyAspect {

    public void doBefore(JoinPoint joinPoint) {
        System.out.println("before 通知发生了");
        System.out.println("正在对run方法增强");
        //返回增强该方法的方法名
        System.out.println("dofore----" + joinPoint.getSignature().getName());

        Object[] objects = joinPoint.getArgs();
        for (Object obj : objects) {
//            System.out.println("obj----"+obj.toString());
            System.out.println("obj-------" + String.valueOf(obj));
        }
        System.out.println("before------" + joinPoint.getArgs());
    }

    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("doAround ------before----------");

        Object obj = joinPoint.proceed(new Object[]{"BBBB", "CCCC"});
        Object[] objects = joinPoint.getArgs();
        for (Object obj1 : objects) {
            System.out.println("obj----------" + obj1);
        }

        System.out.println("doAround-------after-----------");
//        return joinPoint.proceed();
        return obj;
    }

    public void doAfterReturning(JoinPoint joinPoint, String result) {
        System.out.println("doAfterReturning---------------" + result);
    }

    public void doAfter(JoinPoint joinPoint) {
        System.out.println("doAfter----------");
    }

    public void doAfterThrowing(JoinPoint joinPoint, Throwable ex) {
        ex.printStackTrace();
        System.out.println("doAfterThrowing-----------");

    }
}

